4 ...\PTVR_Researchers\Python_Scripts\Experiments\visual_search.py
8 When using a pointer, it is necessary to specify your headset's manufacturer:
9 headset_manufacturer = "Vive" (default) refers to the HTC Vive pro series headsets.
10 headset_manufacturer = "Oculus" refers to the Quest 1, 2 or 3 headsets (in keeping
11 with OpenXR terminology).
13 my_world = The3DWorld (
14 headset_manufacturer = "Vive" # "Vive" by default
24 from PTVR.Data.Callback import AddInteractionPassedToCallback, EndCurrentScene,ChangeObjectOutline,ChangeAudioSettings
26 from numpy
import array
36 viewpoint_position = array ([0, height_of_head, 0])
42 number_of_distractor = 512
44 radial_distance_min_max_values = array([2, 15])
53 hand = LaserContingency.RIGHT_HAND
61 headset_manufacturer =
"Vive"
69 sound_end_of_block =
"applaudisement.mp3"
70 sound_wrong_response =
"buzzer.ogg"
71 handcontroller_id = my_world.handControllerRight.id
72 configurations_set = set()
75 if(random_value == 1):
76 value = random.randint (0, 1)
78 color_object = color_base
80 color_object = color_distractor
82 my_object =
Sphere(size_in_meters= array([0.2, 0.2, 0.2]), color = color_object)
84 my_object =
Cube(size_in_meters= array([0.2, 0.2, 0.2]), color = color_base)
88 reticle_pointing_at_object = PointedAt (target_id = my_object.id,
89 activation_cone_origin_id=handcontroller_id,
90 activation_cone_radius_deg=1, activation_cone_depth=500, mode=
"press",
91 event_name=
"object_is_pointed_at")
92 reticle_NOT_pointing_at_object = PointedAt (target_id = my_object.id,
93 activation_cone_origin_id=handcontroller_id,
94 activation_cone_radius_deg=1, activation_cone_depth=500, mode=
"release",
95 event_name=
"object_is_not_pointed_at")
96 return reticle_pointing_at_object, reticle_NOT_pointing_at_object
104 return callback_outline_on,callback_outline_off
107 print(
"Creating an experiment to study visual search in various 3D regions...")
109 my_initial_scene = CheckScene ( my_world = my_world,
110 are_both_hand_controllers_visible=
True,
111 text_information =
"In this experiment you have "\
112 "to search for the red cube \n among over objects " \
113 "by pointing at it and pressing the trigger.\n" \
114 "When you are ready to start, please press the trigger.")
115 my_world.add_scene (my_initial_scene)
118 my_scene = VisualScene (is_right_hand_controller_visible =
True)
121 my_laser_beam = PointingLaser ( laser_hand = hand,
122 laser_color = my_laser_color,
124 my_scene.place_pointing_laser ( my_laser_beam )
125 my_scene.AddPointingCursor(my_laser_beam)
128 my_world.translate_coordinate_system_along_current(translation = viewpoint_position)
130 audio_wrong =
AudioSource(audio_file=sound_wrong_response, is_playing_directly=
False)
131 my_scene.place(audio_wrong,my_world)
132 while len(configurations_set) < number_of_distractor+1:
134 radialdistance = random.uniform(radial_distance_min_max_values [0],
135 radial_distance_min_max_values [1])
136 eccentricity = random.gauss(90, 40)
137 halfmeridian = random.randint(0, 360)
138 configuration = (radialdistance, eccentricity, halfmeridian)
139 if tuple(configuration)
not in configurations_set:
140 configurations_set.add(tuple(configuration))
142 configurations = [list(config)
for config
in configurations_set]
143 target_configuration = random.choice(configurations)
144 print(
"my target is at np.array([radial_distance,eccentricity,half_meridian)) : " +
145 str(target_configuration))
146 for config
in configurations:
147 radialdistance = config[0]
148 eccentricity = config[1]
149 halfmeridian = config[2]
150 if(config != target_configuration):
153 my_object =
Cube(size_in_meters= array([0.2, 0.2, 0.2]), color=color_target)
154 my_object.set_perimetric_coordinates(radialDistance=radialdistance,
155 eccentricity=eccentricity, halfMeridian=halfmeridian)
156 my_scene.place(my_object, my_world)
157 inside,outside = create_events_when_pointing_at_objects (my_object)
160 press =
HandController(valid_responses=[
'right_trigger'],mode=
"press",event_name=
"press")
161 if(config != target_configuration):
166 my_scene.AddInteraction(events=[inside], callbacks=[add,outline_on])
167 my_scene.AddInteraction(events=[outside], callbacks=[remove,outline_off])
175 my_scene.AddInteraction(events=[inside], callbacks=[add,outline_on])
176 my_scene.AddInteraction(events=[outside], callbacks=[remove,outline_off])
179 my_world.add_scene(my_scene)
181 my_world.reset_coordinate_system()
183 calibration =
CheckScene(my_world = my_world,text_information=
"Congratulations!",are_both_hand_controllers_visible =
True)
185 calibration.place(audio,my_world)
186 my_world.add_scene(calibration)
189 print(
"The .json file corresponding to this experiment has been created.")
192 if __name__ ==
"__main__":
def LaunchThe3DWorld(jsonFileCategory="Externals")
def new_objects(random_value)
def create_events_when_pointing_at_objects(my_object)
def create_callbacks_to_change_objects(my_object)